package core;
import java.awt.*;

import core.units.Unit;
import java.applet.*;
import java.math.*;
import javax.swing.*;
import java.lang.*;

public class PositionChoice {
	int x1, y1, x2, y2;
	double optionPlace=0;
	double actionDir=0;
	boolean rising=true;
	boolean followUnit=false;
	Unit unit;
	int length = 0;
	String followingAction;
	
	public PositionChoice(int inX, int inY, int inLength){
		x1 = inX;
		y1 = inY;
		length = inLength;
		x2 = (int)(x1+Math.cos(actionDir*3.1415*2)*length);
		y2 = (int)(y1+Math.sin(actionDir*3.1415*2)*length);
	}
	public PositionChoice(int inX, int inY, int inLength, double inDir){
		x1 = inX;
		y1 = inY;
		actionDir = inDir;
		length = inLength;
		x2 = (int)(x1+Math.cos(actionDir*3.1415*2)*length);
		y2 = (int)(y1+Math.sin(actionDir*3.1415*2)*length);
	}
	public PositionChoice(Point p, int inLength, double inDir){
		this(p.x, p.y, inLength, inDir);
	}
	public PositionChoice(Unit u, int inLength, double inDir){
		this(u.getPoint(), inLength, inDir);
		followUnit=true;
		unit=u;
	}
	
	
	public void nextFrame(){
		if(rising)
			optionPlace++;
		else
			optionPlace--;
		if(optionPlace>=100)
			rising=false;
		if(optionPlace<=0)
			rising=true;
		if(followUnit){
			x1=unit.getX();
			y1=unit.getY();
		}
			
	}
	
	public void paint(Graphics g){
		g.setColor(Color.white);
		g.drawLine(x1, y1, x2, y2);
		g.fillOval((int)(x1+(x2-x1)*optionPlace/100-5), (int)(y1+(y2-y1)*optionPlace/100-5), 10, 10);
	}
	public void paint(Point screenOffset, int zoomDivider, Graphics g){
		int drawX1, drawY1, drawX2, drawY2;
		g.setColor(Color.white);
		drawX1 = (x1-screenOffset.x)/zoomDivider;
		drawY1 = (y1-screenOffset.y)/zoomDivider;
		drawX2 = (x2-screenOffset.x)/zoomDivider;
		drawY2 = (y2-screenOffset.y)/zoomDivider;
		g.drawLine(drawX1, drawY1, drawX2, drawY2);
		g.fillOval((int)(drawX1+(drawX2-drawX1)*optionPlace/100-5), (int)(drawY1+(drawY2-drawY1)*optionPlace/100-5), 10, 10);
	}
	public int getX(){
		return (int)(x1+(x2-x1)*optionPlace/100-5);
	}
	public int getY(){
		return (int)(y1+(y2-y1)*optionPlace/100-5);
	}
	public Point getPoint(){
		return new Point(getX(), getY());
	}
	public int getOptionPlace(){
		return (int)(optionPlace);
	}
	public void setX(int inX) {
		x1 = inX;
		x2 = (int)(x1+Math.cos(actionDir*3.1415*2)*length);
	}
	public void setY(int inY) {
		y1 = inY;
		y2 = (int)(y1+Math.sin(actionDir*3.1415*2)*length);
	}
}
